<template lang="">
  <div>
    <div class="form_order">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-row style="margin-bottom: 25px">
          <el-col :span="24">
            <span style="font-size: 20px">当前订单审核流程：</span>
            <div
              v-for="(item, index) in AuditList"
              :key="item.id"
              style="display: inline; margin-left: 15px"
            >
              <span
                style="color: #e71f11; font-size: 22px"
                v-if="item.status == 1"
                >{{ index + 1 }}:{{ item.audit_name }}</span
              >
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品类型" prop="type">
              <el-select
                v-model="type"
                placeholder="请选择产品类型"
                clearable
                style="width: 100%"
                @change="type_change"
              >
                <el-option label="半成品" :value="2"> </el-option>
                <el-option label="成品" :value="1"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="模型" prop="modelid">
              <el-select
                v-model="ruleForm.modelid"
                clearable
                placeholder="请选择产品模型"
                style="width: 100%"
                @change="modelid_change"
              >
                <el-option
                  v-for="item in ModelList"
                  :key="item.modelid"
                  :label="item.modelname"
                  :value="item.modelid"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="forEachs('is_replenishment')">
            <el-form-item label="是否补录" :prop="required('is_replenishment')">
              <el-radio-group
                v-model="ruleForm.is_replenishment"
                :disabled="disableds"
              >
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center" v-if="FieldList.length > 0"
          >基础属性</el-divider
        >
        <div class="list_order" v-if="FieldList.length > 0">
          <div class="lis" v-if="forEachs('serial_number')">
            <el-form-item label="流水号" :prop="required('serial_number')">
              <el-input
                v-model="ruleForm.serial_number"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('order_number')">
            <el-form-item label="订单号" :prop="required('order_number')">
              <el-input
                v-model="ruleForm.order_number"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('order_date')">
            <el-form-item label="下单日期" :prop="required('order_date')">
              <el-date-picker
                v-model="ruleForm.order_date"
                :disabled="disableds"
                type="date"
                format="yyyy 年 MM 月 dd 日"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('delivery_date')">
            <el-form-item label="交货日期" :prop="required('delivery_date')">
              <el-date-picker
                v-model="ruleForm.delivery_date"
                :disabled="disableds"
                type="date"
                format="yyyy 年 MM 月 dd 日"
                style="width: 100%"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('customer_id')">
            <el-form-item label="客户" :prop="required('customer_id')">
              <el-select
                filterable
                @change="customer_change"
                v-model="ruleForm.customer_id"
                :disabled="disableds"
                placeholder="请选择客户"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in CustomerList"
                  :key="index"
                  :label="item.customer_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('account_executive_id')">
            <el-form-item
              label="业务员"
              :prop="required('account_executive_id')"
            >
              <el-select
                filterable
                @change="account_executive_change"
                v-model="ruleForm.account_executive_id"
                :disabled="disableds"
                placeholder="请选择业务员"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in EmployeeList"
                  :key="index"
                  :label="item.company_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('emergency_procedure')">
            <el-form-item
              label="紧急程度"
              :prop="required('emergency_procedure')"
            >
              <el-radio-group
                v-model="ruleForm.emergency_procedure"
                :disabled="disableds"
              >
                <el-radio label="1">普通</el-radio>
                <el-radio label="2">紧急</el-radio>
                <el-radio label="3">十万火急</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('is_stock_up')">
            <el-form-item label="是否备货" :prop="required('is_stock_up')">
              <el-radio-group
                v-model="ruleForm.is_stock_up"
                :disabled="disableds"
              >
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
          <!-- <div
            class="lis"
            v-if="ruleForm.is_replenishment == 1 && forEachs('num')"
          >
            <el-form-item label="件数" :prop="required('num')">
              <el-input
                v-model="ruleForm.num"
                type="number"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div> -->

          <div class="lis" v-if="forEachs('num')">
            <el-form-item label="订单数量" :prop="required('num')">
              <el-input-number
                v-model="ruleForm.num"
                :min="1"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('receivables')">
            <el-form-item label="应收款" :prop="required('receivables')">
              <el-input v-model="ruleForm.receivables"></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('received')">
            <el-form-item label="已收款" :prop="required('received')">
              <el-input v-model="ruleForm.received"></el-input>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('remark')">
            <el-form-item label="备注" :prop="required('remark')">
              <el-input
                v-model="ruleForm.remark"
                type="textarea"
                :disabled="disableds"
              ></el-input>
            </el-form-item>
          </div>
        </div>
        <el-divider content-position="center" v-if="FieldList.length > 0"
          >产品属性</el-divider
        >
        <div class="list_order" v-if="FieldList.length > 0">
          <div class="lis" v-if="forEachs('product_id')">
            <el-form-item label="产品" :prop="required('product_id')">
              <el-select
                filterable
                clearable
                v-model="ruleForm.product_id"
                :disabled="disableds_product"
                placeholder="请选择产品"
                style="width: 100%"
                @change="product_id_change_1"
              >
                <el-option
                  v-for="(item, index) in productList_mx"
                  :key="index"
                  :label="item.product_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('model_number_id')">
            <el-form-item label="型号" :prop="required('model_number_id')">
              <el-select
                filterable
                v-model="ruleForm.model_number_id"
                clearable
                @change="model_number_id_change"
                placeholder="请选择型号"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in ModelNumberList"
                  :key="index"
                  :label="item.model_number"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('color_id')">
            <el-form-item label="颜色" :prop="required('color_id')">
              <el-select
                @change="yanse_change"
                clearable
                filterable
                allow-create
                v-model="ruleForm.color_id"
                :disabled="disableds"
                placeholder="请选择颜色"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in ColorList"
                  :key="index"
                  :label="item.color"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="forEachs('specification_id')">
            <el-form-item label="规格" :prop="required('specification_id')">
              <el-select
                @change="guige_change"
                filterable
                clearable
                allow-create
                v-model="ruleForm.specification_id"
                :disabled="disableds"
                placeholder="请选择规格"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in SpecificationList"
                  :key="index"
                  :label="item.specification"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="lis" v-if="type == 2 && is_danxuan == false">
            <el-form-item label="库存">
              <el-checkbox
                v-model="ruleForm.is_kucun"
                v-if="banchengpins == '床板'"
                true-label="1"
                false-label="2"
                :checked="ruleForm.num < chuangban_num"
                >勾选使用库存 ( {{ chuangban_num }} )</el-checkbox
              >
              <el-checkbox
                v-model="ruleForm.is_kucun"
                v-if="banchengpins == '床头'"
                true-label="1"
                false-label="2"
                :checked="ruleForm.num < chuangban_num"
                >勾选使用库存 ( {{ chuangtou_num }} )</el-checkbox
              >
              <el-checkbox
                v-model="ruleForm.is_kucun"
                v-if="banchengpins == '床帮'"
                true-label="1"
                false-label="2"
                :checked="ruleForm.num < chuangban_num"
                >勾选使用库存 ( {{ chuangbang_num }} )</el-checkbox
              >
              <el-checkbox
                v-model="ruleForm.is_kucun"
                v-if="banchengpins == '床头柜'"
                true-label="1"
                false-label="2"
                :checked="ruleForm.num < chuangban_num"
                >勾选使用库存 ( {{ chuangtougui_num }} )</el-checkbox
              >
            </el-form-item>
          </div>

          <div class="lis" v-if="forEachs('is_chuangtougui')">
            <el-form-item
              label="是否要床头柜"
              :prop="required('is_chuangtougui')"
            >
              <el-checkbox-button
                v-model="ruleForm.is_chuangtougui"
                true-label="1"
                false-label="0"
                @change="is_chuangtougui_change"
                >添加床头柜</el-checkbox-button
              >
            </el-form-item>
          </div>

          <div class="lis" v-if="forEachs('warehouse_id')">
            <el-form-item label="发货仓库" :prop="required('warehouse_id')">
              <el-select
                v-model="ruleForm.warehouse_id"
                :disabled="disableds"
                placeholder="请选择仓库"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in cangkulist"
                  :key="index"
                  :label="item.warehouse_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
              <!-- <el-select
                v-model="ruleForm.goods_shelf_id"
                :disabled="disableds"
                placeholder="请选择货架"
                @change="select_goods_shelf"
                style="width: 50%; margin-left: 1%"
              >
                <el-option
                  v-for="(item, index) in huojialist"
                  :key="index"
                  :label="item.goods_shelf_name"
                  :value="item.id"
                >
                </el-option>
              </el-select> -->
            </el-form-item>
          </div>
        </div>
        <el-divider
          content-position="center"
          v-if="FieldList.length > 0 && type == 1 && ban_product.length > 0"
          >半成品</el-divider
        >
        <div class="list_orders">
          <!-- <el-checkbox-group
            v-model="checkList"
            @change="checkbox_change"
            class="list_orders_checked"
          > -->
          <el-row>
            <el-col :span="8">
              <el-row
                v-for="(item, index) in ban_product"
                :key="index"
                v-if="item.modelname == '床板'"
                style="display: flex; align-items: center; margin-top: 10px"
                ><el-col :span="3" style="text-align: center"> 床板 </el-col>
                <el-col :span="13">
                  <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    clearable
                    style="width: 100%"
                    @change="
                      ban_product_model_number(item.modelname, item.product_id)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-col>
                <el-col
                  :span="8"
                  style="text-align: center"
                  v-if="is_danxuan == false"
                >
                  <el-checkbox
                    v-model="item.is_kucun"
                    true-label="1"
                    false-label="2"
                    :checked="ruleForm.num < chuangban_num"
                    >勾选使用库存 ( {{ chuangban_num }} )</el-checkbox
                  >
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="8">
              <el-row
                v-for="(item, index) in ban_product"
                :key="index"
                v-if="item.modelname == '床帮'"
                style="display: flex; align-items: center; margin-top: 10px"
              >
                <el-col :span="3"> 床帮 </el-col>
                <el-col :span="13">
                  <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    clearable
                    style="width: 100%"
                    @change="
                      ban_product_model_number(item.modelname, item.product_id)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-col>

                <el-col
                  :span="8"
                  style="text-align: center"
                  v-if="is_danxuan == false"
                >
                  <el-checkbox
                    v-model="item.is_kucun"
                    true-label="1"
                    false-label="2"
                    :checked="ruleForm.num < chuangban_num"
                    >勾选使用库存 ( {{ chuangbang_num }} )</el-checkbox
                  >
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="8">
              <el-row
                v-for="(item, index) in ban_product"
                :key="index"
                v-if="item.modelname == '床头'"
                style="display: flex; align-items: center; margin-top: 10px"
              >
                <el-col :span="3"> 床头 </el-col>
                <el-col :span="16">
                  <el-select
                    v-model="item.product_id"
                    placeholder="请选择子产品"
                    style="width: 100%"
                    clearable
                    @change="
                      ban_product_model_number(item.modelname, item.product_id)
                    "
                  >
                    <el-option
                      v-for="item in item.select_product"
                      :key="item.id"
                      :label="item.product_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-col>
                <el-col
                  :span="8"
                  style="text-align: center"
                  v-if="is_danxuan == false"
                >
                  <el-checkbox
                    v-model="item.is_kucun"
                    true-label="1"
                    false-label="2"
                    :checked="ruleForm.num < chuangban_num"
                    >勾选使用库存( {{ chuangtou_num }} )</el-checkbox
                  >
                </el-col>
              </el-row>
            </el-col>
          </el-row>
          <el-row
            v-for="(item, index) in ban_product"
            :key="index"
            v-if="item.modelname == '床头柜' && ruleForm.is_chuangtougui == 1"
            style="display: flex; align-items: center; margin-top: 10px"
          >
            <el-col :span="1" style="text-align: center"> 床头柜 </el-col>
            <el-col :span="7">
              <el-select
                v-model="item.product_id"
                placeholder="请选择子产品"
                style="width: 100%"
                clearable
                @change="
                  ban_product_model_number(item.modelname, item.product_id)
                "
              >
                <el-option
                  v-for="item in item.select_product"
                  :key="item.id"
                  :label="item.product_name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col>
            <!-- <el-col :span="1" style="text-align: center"> 型号 </el-col>
            <el-col :span="7">
              <el-select
                v-model="item.model_number_id"
                placeholder="请选择型号"
                style="width: 100%"
                @change="chuangtougui_mode(item.model_number_id)"
              >
                <el-option
                  v-for="item in item.select_product_model"
                  :key="item.id"
                  :label="item.model_number"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-col> -->
            <el-col :span="1" style="text-align: center">数量</el-col>
            <el-col :span="3">
              <el-input-number
                style="width: 100%"
                v-model="item.chuangtougui_num"
                :min="1"
              ></el-input-number>
            </el-col>
            <el-col
              :span="4"
              style="text-align: center"
              v-if="is_danxuan == false"
            >
              <el-checkbox
                v-model="item.is_kucun"
                true-label="1"
                false-label="2"
                :checked="ruleForm.num < chuangban_num"
                >勾选使用库存 ( {{ chuangtougui_num }} )</el-checkbox
              >
            </el-col>
          </el-row>
          <!-- </el-checkbox-group> -->
        </div>
        <el-divider
          content-position="center"
          v-if="FieldList.length > 0 && FieldList_new.length > 0"
          >额外属性</el-divider
        >
        <div class="list_order" v-if="FieldList.length > 0">
          <div class="lis" v-for="(item, index) in FieldList_new" :key="index">
            <el-form-item :label="item.name">
              <el-input
                v-if="item.formtype == 'input'"
                v-model="item.default_value"
                type="input"
              ></el-input>

              <el-select
                v-if="item.formtype == 'select'"
                v-model="item.default_value"
                placeholder="请选择"
              >
                <el-option
                  v-for="(ite, index) in item.option_list"
                  :key="index"
                  :label="ite.option_name"
                  :value="ite.option_id"
                >
                </el-option>
              </el-select>
              <el-radio-group
                v-if="item.formtype == 'radio'"
                v-model="item.default_value"
              >
                <el-radio
                  v-for="(ite, index) in item.option_list"
                  :key="index"
                  :label="ite.option_id"
                  >{{ ite.option_name }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <el-button
        type="primary"
        size="small"
        style="
          display: block;
          margin: 0 auto;
          width: 100px;
          background-color: green;
          margin-top: 20px;
        "
        @click="submitadds('ruleForm')"
        >确认</el-button
      >
    </div>
    <div class="order_list">
      <el-table
        :data="dataList"
        sortable
        :default-sort="{ prop: 'serial_number', order: 'ascending' }"
        stripe
        style="width: 100%"
        border
      >
        <el-table-column
          prop="serial_number"
          label="流水号"
          width="100"
          v-if="forEachs('serial_number') || isshow"
        >
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单号"
          width="100"
          v-if="forEachs('order_number') || isshow"
        >
        </el-table-column>
        <el-table-column
          label="客户"
          width="100"
          v-if="forEachs('customer_id') || isshow"
        >
          <template slot-scope="scope">
            <span>{{
              scope.row.customer_name ? scope.row.customer_name : "备货"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="product_name"
          label="产品"
          width="80"
          v-if="forEachs('product_id') || isshow"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.product_name }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="model_number"
          label="型号"
          width="80"
          v-if="forEachs('model_number_id') || isshow"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.model_number }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="color"
          label="规格"
          width="80"
          v-if="forEachs('specification_id') || isshow"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.specification }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="color"
          label="颜色"
          width="80"
          v-if="forEachs('color_id') || isshow"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.color }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="direction" label="大小" width="120" >
      </el-table-column> -->
        <el-table-column
          prop="num"
          label="数量"
          width="80"
          v-if="forEachs('direction') || isshow"
        >
        </el-table-column>
        <el-table-column
          label="紧急程度"
          width="80"
          prop="emergency_procedure"
          v-if="forEachs('emergency_procedure') || isshow"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.emergency_procedure == 1" style="color: #333"
              >普通</span
            >
            <span
              v-if="scope.row.emergency_procedure == 2"
              style="color: #1890ff; font-weight: bold"
              >紧急</span
            >
            <span
              v-if="scope.row.emergency_procedure == 3"
              style="color: #ff0000; font-weight: bold"
              >十万火急</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="remark"
          label="备注"
          width="120"
          v-if="forEachs('remark') || isshow"
        >
        </el-table-column>
        <el-table-column
          label="业务员"
          width="80"
          v-if="forEachs('account_executive_id') || isshow"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.account_executive }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column
          label="业务员"
          v-if="forEachs('account_executive_id') || isshow"
        >
          <template slot-scope="scope">
            {{
              scope.row.account_executive
                ? scope.row.account_executive.company_name
                : ""
            }}
          </template>
        </el-table-column> -->
        <el-table-column
          v-if="forEachs('order_date') || isshow"
          prop="order_date"
          label="订单日期"
          :formatter="formatterTime"
          width="100"
        >
        </el-table-column>
        <el-table-column
          v-if="forEachs('delivery_date') || isshow"
          prop="delivery_date"
          label="交货日期"
          :formatter="formatterTime"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="receivables"
          label="应收款"
          width="80"
          v-if="forEachs('receivables') || isshow"
        >
        </el-table-column>
        <el-table-column
          prop="received"
          label="已收款"
          width="80"
          v-if="forEachs('received') || isshow"
        >
        </el-table-column>
        <el-table-column
          label="是否补货"
          width="80"
          v-if="forEachs('is_replenishment') || isshow"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.is_replenishment == 1">是</span>
            <span v-if="scope.row.is_replenishment == 2">否</span>
          </template>
        </el-table-column>
        <el-table-column
          label="是否备货"
          width="80"
          v-if="forEachs('is_stock_up') || isshow"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.is_stock_up == 1">是</span>
            <span v-if="scope.row.is_stock_up == 2">否</span>
          </template>
        </el-table-column>
        <div v-for="(item, index) in dataList.models_field" :key="index">
          <el-table-column :prop="item" :label="push_name(item)">
          </el-table-column>
        </div>
        <el-table-column label="操作" width="150" fixed="right">
          <template slot-scope="scope">
            <el-button @click="set_product(scope.row)" type="text"
              >编辑</el-button
            >
            <el-popconfirm
              v-permission="['dingdan_shanchu']"
              confirm-button-text="确定"
              cancel-button-text="取消"
              icon="el-icon-info"
              icon-color="red"
              title="确定删除此订单吗？"
              @confirm="del_Order(scope.$index)"
            >
              <el-button slot="reference" size="small" type="text"
                >删除</el-button
              >
            </el-popconfirm>
            <el-button
              v-if="scope.$index == dataList.length - 1"
              @click="set_products(scope.row)"
              type="text"
              >复制</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div
        style="
          margin: 0 auto;
          width: 230px;
          display: flex;
          justify-content: space-between;
        "
      >
        <el-popconfirm
          v-permission="['dingdan_shanchu']"
          confirm-button-text="确定"
          cancel-button-text="取消"
          icon="el-icon-info"
          icon-color="red"
          title="是否放弃提交订单！？"
          @confirm="dels_Order"
        >
          <el-button
            slot="reference"
            size="small"
            type="primary"
            style="
              width: 100px;
              height: 32px;
              background-color: red;
              border: none;
            "
            >取 消</el-button
          >
        </el-popconfirm>
        <el-button
          type="primary"
          size="small"
          @click="submitadds_s('ruleForm')"
          style="width: 100px; background-color: green"
          >提交订单</el-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import {
  getModelList,
  getOrderAuditList,
  getProductList,
  getProductFieldList,
  automaticGenerationOrderNumber,
  automaticGenerationSerialNumber,
  getProductColorList,
  getModelNumberList,
  getCustomerList,
  createColor,
  getSpecificationList,
  getColorList,
  getProductInfoByModelNumberId,
  getModelNumberListByProduct,
  getColorByModelNumberId,
  createOrder,
  getInventoryCount,
  getWarehouseList,
} from "@/api/product/index";
import { getYeWuYuanList } from "@/api/user";
export default {
  data() {
    return {
      is_danxuan: false,
      checkList: [1, 1, 1],
      isset: false,
      isadd: true,
      ban_product: [],
      isshow: true,
      type: "",
      disableds: false,
      disableds_product: false,
      ruleForm: {
        modelid: "",
        num: "",
        warehouse_id: "",
        goods_shelf_id: "",
        batch_number: "",
        serial_number: "",
        order_number: "",
        order_date: "",
        delivery_date: "",
        account_executive_id: "",
        product_id: "",
        model_number_id: "",
        color_id: "",
        size: "",
        is_chuangtougui: 0,
        specification_id: "",
        direction: "",
        customer_id: "",
        received: "",
        emergency_procedure: "1",
        is_replenishment: "2",
        is_stock_up: "2",
        receivables: "",
        remark: "",
        id: "",
        is_kucun: "2",
        chuangban: {
          product_id: "",
        },
        chuangbang: {
          product_id: "",
        },
        chuangtou: {
          product_id: "",
        },
        chuangtougui: {
          product_id: "",
        },
      },
      rules: {
        num: [{ required: true, message: "请输入数量", trigger: "blur" }],
        warehouse_id: [
          { required: true, message: "请选择仓库", trigger: "blur" },
        ],
        goods_shelf_id: [
          { required: true, message: "请选择货架", trigger: "blur" },
        ],
        batch_number: [
          {
            required: true,
            message: "请输入生产批号",
            trigger: "blur",
          },
        ],
        specification_id: [
          {
            required: true,
            message: "请选择规格",
            trigger: "blur",
          },
        ],
        serial_number: [
          {
            required: true,
            message: "请输入流水号",
            trigger: "blur",
          },
        ],
        order_number: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        order_date: [
          {
            required: true,
            message: "请选择下单日期",
            trigger: "blur",
          },
        ],
        delivery_date: [
          {
            required: true,
            message: "请选择交货日期",
            trigger: "blur",
          },
        ],
        account_executive_id: [
          {
            required: true,
            message: "请选择员工",
            trigger: "blur",
          },
        ],
        product_id: [
          {
            required: true,
            message: "请选择产品",
            trigger: "blur",
          },
        ],
        model_number_id: [
          {
            required: true,
            message: "请选择型号",
            trigger: "blur",
          },
        ],
        color_id: [
          {
            required: true,
            message: "请选择颜色",
            trigger: "blur",
          },
        ],
        size: [
          {
            required: true,
            message: "请选择规格",
            trigger: "blur",
          },
        ],
        direction: [
          {
            required: true,
            message: "请输入产品方向",
            trigger: "blur",
          },
        ],
        customer_id: [
          {
            required: true,
            message: "请选择客户",
            trigger: "blur",
          },
        ],
        emergency_procedure: [
          {
            required: true,
            message: "请选择紧急程度",
            trigger: "blur",
          },
        ],
        is_replenishment: [
          {
            required: true,
            message: "是否补货",
            trigger: "blur",
          },
        ],
        received: [
          {
            required: true,
            message: "请输入应收款",
            trigger: "blur",
          },
        ],
        receivables: [
          {
            required: true,
            message: "请输入已收款",
            trigger: "blur",
          },
        ],
        is_stock_up: [
          {
            required: true,
            message: "是否备货",
            trigger: "blur",
          },
        ],
        receivables: [
          {
            required: true,
            message: "请输入应收款金额",
            trigger: "blur",
          },
        ],
      },
      directionList: [
        {
          name: "左",
        },
        {
          name: "右",
        },
        {
          name: "无",
        },
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      formatterTime(row, column) {
        let data = row[column.property];
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
      },
      dataList: [],
      dataLists: [],
      AuditList: [],
      ModelList: [],
      FieldList: [],
      FieldList_new: [],
      productList_mx: [],
      ModelNumberList: [],
      ColorList: [],
      SpecificationList: [],
      CustomerList: [],
      EmployeeList: [],
      ModelNumberList_s1: [],
      ModelNumberList_s2: [],
      ModelNumberList_s3: [],
      chuangtou_num: 0,
      chuangtougui_num: 0,
      chuangbang_num: 0,
      chuangban_num: 0,
      ruleForms: [],
      chuangtougui_id: "",
      banchengpins: "",
    };
  },
  mounted() {
    this.get_ModelList();
    this.get_OrderAuditList();
    this.getCustomer();
    this.getEmpl();
    this.getproduct();
    this.get_ColorList();
    this.get_SpecificationList();
    this.getcangku();
  },
  watch: {
    "ruleForm.product_id"(newval, oldvals) {
      if (this.type == 2) {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount(item.modelname);
          }
        });
      }
    },
    "ruleForm.model_number_id"(newval, oldvals) {
      if (this.type == 2) {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount(item.modelname);
          }
        });
      }
    },
    "ruleForm.color_id"(newval, oldvals) {
      if (this.type == 2) {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount(item.modelname);
          }
        });
      }
    },
    "ruleForm.specification_id"(newval, oldvals) {
      if (this.type == 2) {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount(item.modelname);
          }
        });
      }
    },

    "ruleForm.warehouse_id"(newval, oldvals) {
      if (newval) {
        if (this.type == 1) {
          if (this.ruleForm.is_chuangtougui == 1) {
            this.foreach_ban_product();
          } else {
            this.foreach_ban_products();
          }
        } else {
          this.ModelList.forEach((item) => {
            if (item.modelid == this.ruleForm.modelid) {
              this.get_InventoryCount(item.modelname);
            }
          });
        }
      }
    },
    "ruleForm.is_replenishment"(newval, oldvals) {
      if (newval == 1) {
        this.is_danxuan = true;
      } else {
        this.is_danxuan = false;
      }
    },
    "ruleForm.is_stock_up"(newval, oldvals) {
      if (newval == 1) {
        this.is_danxuan = true;
      } else {
        this.is_danxuan = false;
      }
    },
    "ruleForm.is_chuangtougui"(newval, oldvals) {
      console.log(newval);
      console.log(oldvals);
      if (newval == 1) {
        this.ban_product.forEach((item) => {
          if (item.modelname == "床头柜") {
            item.product_id = item.select_product[0].id;
            this.ban_product_model_number("床头柜", item.product_id);
          }
        });
      }
    },
    ban_product(newval, oldvals) {
      if (newval.length > 0 && this.ruleForm.is_chuangtougui == 1) {
        this.ban_product.forEach((item) => {
          if (item.modelname == "床头柜") {
            item.product_id = item.select_product[0].id;
            // this.get_producModel_s1(item.select_product[0].id);
            console.log(item.product_id);
            this.ban_product_model_number("床头柜", item.product_id);
            return false;
          }
        });
      }
      if (newval.length == 4) {
        console.log(newval);
        newval.forEach((item) => {
          if (item.modelname == "床板") {
            let chuangtou = {
              modelid: item.modelid,
              product_id: item.product_id,
              model_number_id: "",
              is_kucun: item.is_kucun,
            };
            this.$set(this.ruleForm, "chuangban", chuangtou);
          }

          if (item.modelname == "床帮") {
            let chuangtou = {
              modelid: item.modelid,
              product_id: item.product_id,
              model_number_id: "",
              is_kucun: item.is_kucun,
            };
            this.$set(this.ruleForm, "chuangbang", chuangtou);
          }

          if (item.modelname == "床头柜") {
            let chuangtou = {
              modelid: item.modelid,
              product_id: item.product_id,
              model_number_id: item.model_number_id,
              chuangtougui_num: item.chuangtougui_num,
              is_kucun: item.is_kucun,
            };
            this.$set(this.ruleForm, "chuangtougui", chuangtou);
          }

          if (item.modelname == "床头") {
            let chuangtou = {
              modelid: item.modelid,
              product_id: item.product_id,
              model_number_id: this.ruleForm.model_number_id,
              is_kucun: item.is_kucun,
            };
            this.$set(this.ruleForm, "chuangtou", chuangtou);
          }
        });
      }
    },
  },
  methods: {
    foreach_ban_product() {
      this.ban_product.forEach((item) => {
        this.ban_product_model_number(item.modelname, item.product_id);
      });
    },
    foreach_ban_products() {
      this.ban_product.forEach((item) => {
        if (item.modelname != "床头柜") {
          this.ban_product_model_number(item.modelname, item.product_id);
        }
      });
    },
    getcangku() {
      getWarehouseList({ warehouse_type_id: 1 }).then((res) => {
        if (res.code == 200) {
          this.cangkulist = res.data.data;
          this.ruleForm.warehouse_id = this.cangkulist[0].id;
        }
      });
    },
    is_chuangtougui_change(val) {
      console.log(val);
    },

    checkbox_change() {
      if (this.checkList.includes("床头")) {
        this.$set(this.ruleForm, "is_chuangtou", 1);
      } else {
        this.$set(this.ruleForm, "is_chuangtou", 2);
      }
      if (this.checkList.includes("床头柜")) {
        this.$set(this.ruleForm, "is_chuangtougui", 1);
      } else {
        this.$set(this.ruleForm, "is_chuangtougui", 2);
      }
      if (this.checkList.includes("床板")) {
        this.$set(this.ruleForm, "is_chuangban", 1);
      } else {
        this.$set(this.ruleForm, "is_chuangban", 2);
      }
      if (this.checkList.includes("床帮")) {
        this.$set(this.ruleForm, "is_chuangbang", 1);
      } else {
        this.$set(this.ruleForm, "is_chuangbang", 2);
      }
      console.log(this.ruleForm, this.checkList);
    },
    type_change(val) {
      this.ruleForm.modelid = "";
      this.productList_mx = [];
      this.ModelNumberList = [];
      this.FieldList = [];
      this.ban_product = [];
      this.get_ModelList(val);
    },
    model_number_id_change(val) {
      this.get_ColorByModelNumberId(val);
      for (let i = 0; i < this.ModelNumberList.length; i++) {
        if (val == this.ModelNumberList[i].id) {
          this.$set(
            this.ruleForm,
            "model_number",
            this.ModelNumberList[i].model_number
          );
        }
      }
      if (this.type == 1) {
        this.get_SemiListByProductId(val);
      }
    },
    get_ColorByModelNumberId(id) {
      getColorByModelNumberId({ model_number_id: id }).then((res) => {
        if (res.code == 200) {
          this.ruleForm.color_id = res.data;
        }
      });
    },
    get_SemiListByProductId(val) {
      this.ban_product = [];
      getProductInfoByModelNumberId({
        modelid: this.ruleForm.modelid,
        model_number_id: val,
      }).then((res) => {
        if (res.code == 200) {
          this.SemiList = res.data;
          this.SemiList.forEach((item) => {
            getProductList({ is_dropdown: 1, modelid: item.modelid }).then(
              (res) => {
                if (res.code == 200) {
                  let obj = {
                    modelid: item.modelid,
                    modelname: item.modelname,
                    color_essential: "",
                    color_shelf: "",
                    color_match: "",
                    select_product: res.data,
                    select_product_model: [],
                    product_id: item.default ? item.default.product_id : "",
                    model_number_id: "",
                    chuangtougui_num: "",
                    is_kucun: "",
                  };
                  this.ban_product.push(obj);
                }
              }
            );
          });
        }
      });
    },
    get_SpecificationList() {
      getSpecificationList().then((res) => {
        if (res.code == 200) {
          this.SpecificationList = res.data.data;
        }
      });
    },
    numzhu(str) {
      const regex = /\d+/; // 匹配数字的正则表达式
      const result = str.replace(regex, (match) => {
        const number = Number(match); // 将匹配到的数字转换为整数
        console.log(number);
        const incrementedNumber = number + 1; // 加1
        return incrementedNumber.toString(); // 将结果转换为字符串
      });
      console.log(result);
      return result;
    },
    set_products(row) {
      console.log(row);
      let rows = JSON.parse(JSON.stringify(row));
      let serial_number = this.numzhu(rows.serial_number.toString());
      let order_number = this.numzhu(rows.order_number.toString());

      this.ruleForm.serial_number = serial_number;
      this.ruleForm.order_number = order_number;

      rows.serial_number = serial_number;
      rows.order_number = order_number;
      var that = this;
      setTimeout(() => {
        that.dataList.push(rows);
      }, 300);
    },
    set_product(row) {
      this.ruleForms = JSON.parse(JSON.stringify(row));
      this.ruleForm = this.ruleForms;
      this.isset = true;
      this.isadd = false;
    },
    get_ColorList() {
      getColorList({ per_page: 1000 }).then((res) => {
        if (res.code == 200) {
          this.ColorList = res.data.data;
        }
      });
    },
    dels_Order() {
      this.$router.push("/order_goods/order_goods");
    },
    del_Order(num) {
      console.log(num);
      this.dataList.splice(num, 1);
      console.log(this.dataList);
    },
    submitadds_s() {
      createOrder({ order_data: this.dataLists }).then((res) => {
        if (res.code == 200) {
          this.$message.success("提交成功");
          this.ruleForm = {};
          this.dataList = [];
          this.FieldList = [];
          this.ban_product = [];
          this.type = "";
          this.$store.state.tagsView.visitedViews.splice(
            this.$store.state.tagsView.visitedViews.findIndex(
              (item) => item.path === this.$route.path
            )
          );
          this.$router.go(-1);
        }
      });
    },

    ban_product_model_number(val, id) {
      if (val == "床板") {
        // this.get_producModel_s1(id);
        this.ruleForm.chuangban.product_id = id;
        let obj = {
          product_id: id,
          // model_number_id: this.ruleForm.model_number_id,
          // color_id: this.ruleForm.color_id,
          specification_id: this.ruleForm.specification_id,
          warehouse_id: this.ruleForm.warehouse_id,
        };
        getInventoryCount(obj).then((res) => {
          if (res.code == 200) {
            this.chuangban_num = res.data;
          }
        });
      }
      if (val == "床帮") {
        // this.get_producModel_s1(id);
        this.ruleForm.chuangbang.product_id = id;
        let obj = {
          product_id: id,
          // model_number_id: this.ruleForm.model_number_id,
          // color_id: this.ruleForm.color_id,
          specification_id: this.ruleForm.specification_id,
          warehouse_id: this.ruleForm.warehouse_id,
        };
        getInventoryCount(obj).then((res) => {
          if (res.code == 200) {
            this.chuangbang_num = res.data;
          }
        });
      }
      if (val == "床头") {
        this.ruleForm.chuangtou.product_id = id;
        // this.get_producModel_s1(id);
        let obj = {
          product_id: id,
          model_number_id: this.ruleForm.model_number_id,
          color_id: this.ruleForm.color_id,
          specification_id: this.ruleForm.specification_id,
          warehouse_id: this.ruleForm.warehouse_id,
        };
        getInventoryCount(obj).then((res) => {
          if (res.code == 200) {
            this.chuangtou_num = res.data;
          }
        });
      }
      if (val == "床头柜") {
        console.log("33333333");
        this.ruleForm.chuangtougui.product_id = id;
        if (this.ruleForm.is_chuangtougui == 1) {
          let obj = {
            product_id: id,
            // model_number_id: '',
            color_id: "",
            // specification_id: '',
            warehouse_id: this.ruleForm.warehouse_id,
          };
          getInventoryCount(obj).then((res) => {
            if (res.code == 200) {
              this.chuangtougui_num = res.data;
            }
          });
        }
      }
    },
    //半成品
    get_InventoryCount(val) {
      if (val == "床板") {
        // this.get_producModel_s1(id);
        let obj = {
          product_id: this.ruleForm.product_id,
          // model_number_id: this.ruleForm.model_number_id,
          // color_id: this.ruleForm.color_id,
          specification_id: this.ruleForm.specification_id,
          warehouse_id: this.ruleForm.warehouse_id,
        };
        getInventoryCount(obj).then((res) => {
          if (res.code == 200) {
            this.chuangban_num = res.data;
          }
        });
      }
      if (val == "床帮") {
        // this.get_producModel_s1(id);
        let obj = {
          product_id: this.ruleForm.product_id,
          // model_number_id: this.ruleForm.model_number_id,
          // color_id: this.ruleForm.color_id,
          specification_id: this.ruleForm.specification_id,
          warehouse_id: this.ruleForm.warehouse_id,
        };
        getInventoryCount(obj).then((res) => {
          if (res.code == 200) {
            this.chuangbang_num = res.data;
          }
        });
      }
      if (val == "床头") {
        // this.get_producModel_s1(id);
        let obj = {
          product_id: this.ruleForm.product_id,
          model_number_id: this.ruleForm.model_number_id,
          color_id: this.ruleForm.color_id,
          specification_id: this.ruleForm.specification_id,
          warehouse_id: this.ruleForm.warehouse_id,
        };
        getInventoryCount(obj).then((res) => {
          if (res.code == 200) {
            this.chuangtou_num = res.data;
          }
        });
      }
      if (val == "床头柜") {
        if (this.ruleForm.is_chuangtougui == 1) {
          let obj = {
            product_id: this.ruleForm.product_id,
            // model_number_id: '',
            color_id: this.ruleForm.color_id,
            // specification_id: '',
            warehouse_id: this.ruleForm.warehouse_id,
          };
          getInventoryCount(obj).then((res) => {
            if (res.code == 200) {
              this.chuangtougui_num = res.data;
            }
          });
        }
      }
    },
    //床头柜型号
    get_producModel_s1(id) {
      this.ruleForm.chuangtougui.product_id = id;
      getModelNumberListByProduct({ product_id: id }).then((res) => {
        if (res.code == 200) {
          let ModelNumberList_s1 = res.data;
          console.log(this.ban_product);
          this.ban_product.forEach((item) => {
            if (item.product_id == id) {
              item.select_product_model = ModelNumberList_s1;
              if (item.modelname != "床头柜") {
                item.model_number_id = "";
              }
            }
          });
        }
      });
    },
    submitadds(formName) {
      this.ban_product.forEach((item) => {
        if (item.modelname == "床板") {
          let chuangtou = {
            modelid: item.modelid,
            product_id: item.product_id,
            model_number_id: "",
            is_kucun: item.is_kucun,
          };
          this.$set(this.ruleForm, "chuangban", chuangtou);
        }

        if (item.modelname == "床帮") {
          let chuangtou = {
            modelid: item.modelid,
            product_id: item.product_id,
            model_number_id: "",
            is_kucun: item.is_kucun,
          };
          this.$set(this.ruleForm, "chuangbang", chuangtou);
        }

        if (item.modelname == "床头柜") {
          let chuangtou = {
            modelid: item.modelid,
            product_id: item.product_id,
            model_number_id: item.model_number_id,
            chuangtougui_num: item.chuangtougui_num,
            is_kucun: item.is_kucun,
          };
          this.$set(this.ruleForm, "chuangtougui", chuangtou);
        }

        if (item.modelname == "床头") {
          let chuangtou = {
            modelid: item.modelid,
            product_id: item.product_id,
            model_number_id: this.ruleForm.model_number_id,
            is_kucun: item.is_kucun,
          };
          this.$set(this.ruleForm, "chuangtou", chuangtou);
        }
      });
      this.$set(this.ruleForm, "pid", this.type);
      // this.$set(this.ruleForm, "child", this.ban_product);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.dataList.length > 0) {
            let arry_serial_number = [];
            let arry_order_number = [];
            for (var i = 0; i < this.dataList.length; i++) {
              arry_serial_number.push(
                this.dataList[i].serial_number.toString()
              );
              arry_order_number.push(this.dataList[i].order_number.toString());
            }
            console.log(arry_serial_number);
            console.log(arry_order_number);
            if (
              arry_serial_number.includes(this.ruleForm.serial_number) &&
              arry_order_number.includes(this.ruleForm.order_number)
            ) {
              console.log("342w354r23");
              for (let i = 0; i < arry_serial_number.length; i++) {
                if (this.ruleForm.serial_number == arry_serial_number[i]) {
                  console.log(i);
                  this.dataList.splice(i, 1);
                  var that = this;
                  setTimeout(function () {
                    that.dataList.push(that.ruleForm);
                  }, 300);
                }
              }
            } else {
              this.dataList.push(JSON.parse(JSON.stringify(this.ruleForm)));
              this.$set(
                this.ruleForm,
                "serial_number",
                this.numzhu(this.ruleForm.serial_number.toString())
              );
              this.$set(
                this.ruleForm,
                "order_number",
                this.numzhu(this.ruleForm.order_number.toString())
              );
            }
          } else {
            this.dataList.push(JSON.parse(JSON.stringify(this.ruleForm)));
            this.$set(
              this.ruleForm,
              "serial_number",
              this.numzhu(this.ruleForm.serial_number.toString())
            );
            this.$set(
              this.ruleForm,
              "order_number",
              this.numzhu(this.ruleForm.order_number.toString())
            );
          }

          this.dataLists = this.dataList;
          this.ban_product = [];

          console.log(this.dataList);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    numzhus(str) {
      const regex = /\d+/; // 匹配数字的正则表达式
      const result = str.replace(regex, (match) => {
        const number = Number(match); // 将匹配到的数字转换为整数
        return number.toString(); // 将结果转换为字符串
      });
      return result;
    },
    // 业务员列表
    getEmpl() {
      getYeWuYuanList().then((res) => {
        if (res.code == 200) {
          this.EmployeeList = res.data;
        }
      });
    },
    yanse_change(val) {
      var list = [];
      for (let i = 0; i < this.ColorList.length; i++) {
        list.push(this.ColorList[i].id);
        if (val == this.ColorList[i].id) {
          this.$set(this.ruleForm, "color", this.ColorList[i].color);
        }
      }
      if (!list.includes(val)) {
        this.create_Color(val);
      }

      if (this.type == 1) {
        this.ban_product_model_number(
          "床板",
          this.ruleForm.chuangban.product_id
        );
        this.ban_product_model_number(
          "床头",
          this.ruleForm.chuangtou.product_id
        );
        this.ban_product_model_number(
          "床帮",
          this.ruleForm.chuangbang.product_id
        );
        this.ban_product_model_number(
          "床头柜",
          this.ruleForm.chuangtougui.product_id
        );
      } else {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount(item.modelname, val);
          }
        });
      }
    },
    create_Color(val) {
      let lists = [];
      let list = [];
      list.push(val);
      lists.push(this.ruleForm.product_id);
      let obj = {
        product_ids: lists,
        color_names: list,
      };
      createColor(obj).then((res) => {
        if (res.code == 200) {
          let lengths = this.ColorList.length;
          this.$set(this.ColorList, lengths, { id: res.data[0], color: val });
          this.get_produccolor(this.ruleForm.product_id);
          let that = this;
          setTimeout(() => {
            that.ruleForm.color_id = res.data[0];
          }, 500);
          console.log(this.ColorList);
        }
      });
    },
    guige_change(val) {
      console.log(val);
      var list = [];
      console.log(this.SpecificationList);
      for (let i = 0; i < this.SpecificationList.length; i++) {
        list.push(this.SpecificationList[i].id);
        if (val == this.SpecificationList[i].id) {
          this.$set(
            this.ruleForm,
            "specification",
            this.SpecificationList[i].specification
          );
        }
      }
      if (!list.includes(val)) {
        this.update_Specification(val);
      }
      console.log(this.ruleForm);
      if (this.type == 1) {
        this.ban_product_model_number(
          "床板",
          this.ruleForm.chuangban.product_id
        );
        this.ban_product_model_number(
          "床头",
          this.ruleForm.chuangtou.product_id
        );
        this.ban_product_model_number(
          "床帮",
          this.ruleForm.chuangbang.product_id
        );
        this.ban_product_model_number(
          "床头柜",
          this.ruleForm.chuangtougui.product_id
        );
      } else {
        this.ModelList.forEach((item) => {
          if (item.modelid == this.ruleForm.modelid) {
            this.get_InventoryCount(item.modelname, val);
          }
        });
      }
    },

    product_id_change_1(val) {
      this.ModelNumberList = [];
      this.ruleForm.model_number_id = "";
      this.get_producModel(val);
      //   this.get_produccolor(val);
      //   this.FieldList_new = FieldList_new;

      this.produc_number_id = val;
      this.ruleForm.product_id = val;
      this.productList_mx.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "product_name", item.product_name);
        }
      });
      // this.get_SemiListByProductId(val)
    },
    auto_maticGenerationOrderNumber() {
      automaticGenerationOrderNumber().then((res) => {
        this.ruleForm.order_number = res.data;
      });
    },
    automatic_GenerationSerialNumber() {
      automaticGenerationSerialNumber().then((res) => {
        this.ruleForm.serial_number = res.data;
      });
      console.log(this.ruleForm.serial_number);
    },
    get_produccolor() {
      getProductColorList().then((res) => {
        if (res.code == 200) {
          this.ColorList = res.data;
        }
      });
    },
    get_producModel(id) {
      getModelNumberListByProduct({ product_id: id }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data;
        }
      });
    },
    select_goods_shelf(val) {
      this.huojialist.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "goods_shelf", item.goods_shelf);
        }
      });
    },
    direction_change(val) {
      this.directionList.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "direction", item.name);
        }
      });
    },
    account_executive_change(val) {
      this.EmployeeList.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "account_executive", item.company_name);
        }
      });
    },
    customer_change(val) {
      this.CustomerList.forEach((item) => {
        if (val == item.id) {
          this.$set(this.ruleForm, "customer_name", item.customer_name);
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    //产品列表
    getproduct_mx(val) {
      getProductList({ is_dropdown: 1, modelid: val }).then((res) => {
        if (res.code == 200) {
          this.productList_mx = res.data;
        }
      });
    },
    get_ProductFieldList(val) {
      getProductFieldList({ modelid: val }).then((res) => {
        if (res.code == 200) {
          this.FieldList = res.data;
          let FieldList_new = [];
          this.FieldList.forEach((item) => {
            if (item.is_default == 2) {
              FieldList_new.push(item);
              this.$set(this.ruleForm, item.field, item.default_value);
            }
          });
          this.FieldList_new=FieldList_new
          console.log(this.FieldList_new)
        }
      });
    },
    // 客户列表
    getCustomer() {
      getCustomerList({ per_page: 99999 }).then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    modelid_change(val) {
      this.ruleForm.product_id = "";
      this.getproduct_mx(val);
      this.get_ProductFieldList(val);
      if (this.dataList.length > 0) {
        console.log(this.dataList[this.dataList.length - 1]);
        this.$set(
          this.ruleForm,
          "serial_number",
          this.numzhu(
            this.dataList[this.dataList.length - 1].serial_number.toString()
          )
        );
        this.$set(
          this.ruleForm,
          "order_number",
          this.numzhu(
            this.dataList[this.dataList.length - 1].order_number.toString()
          )
        );
      } else {
        this.automatic_GenerationSerialNumber();
        this.auto_maticGenerationOrderNumber();
      }

      this.ModelList.forEach((item) => {
        if (item.modelid == val) {
          this.banchengpins = item.modelname;
        }
      });
    },

    get_ModelList() {
      let obj = {
        is_dropdown: 1,
        type: this.type,
      };
      getModelList(obj).then((res) => {
        if (res.code == 200) {
          this.ModelList = res.data;
        }
      });
    },
    get_OrderAuditList() {
      getOrderAuditList().then((res) => {
        if (res.code == 200) {
          this.AuditList = res.data.data;
        }
      });
    },
    push_name(val) {
      console.log(val);
      for (var i = 0; i < this.FieldList_new.length; i++) {
        if (
          val == this.FieldList_new[i].field &&
          this.FieldList_new[i].show == "1"
        ) {
          console.log(this.FieldList_new[i].name);
          return this.FieldList_new[i].name;
        }
      }
    },
    required(val) {
      for (let i = 0; i < this.FieldList.length; i++) {
        if (this.FieldList[i].field == val && this.FieldList[i].required == 1) {
          return this.FieldList[i].field;
        }
      }
    },
    forEachs(val) {
      for (let i = 0; i < this.FieldList.length; i++) {
        if (this.FieldList[i].field == val && this.FieldList[i].show == 1) {
          return true;
        }
      }
    },
  },
};
</script>
<style scoped>
.list_order {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  place-items: left;
}

.list_orders {
  display: grid;
  grid-template-columns: 1fr;
  place-items: left;
}
.list_orders_checked {
  display: grid;
  grid-template-columns: 1fr;
  place-items: left;
  gap: 0 15px;
}
.list_order .lis {
  width: 100%;
}
</style>
